package com.fdm.model.accounts;

import java.util.Map;

import com.fdm.model.exceptions.BankManagerException;
import com.fdm.model.properties.AccountBuilderProperties;

public class AccountFactory 
{
	private AccountBuilderProperties accountBuilderProperties;
	private String [] decorations;
	
	public  AccountFactory(){
		accountBuilderProperties =new AccountBuilderProperties();
	}
	
	public _Account createAccount(String accountType, 
			Map<String,Object> parameters) throws BankManagerException
	{
		if (decorations==null){
			decorations = getDecorations(accountType);
		}
		AccountBuilder builder = new AccountBuilder();
		parameters.put("accountType", accountType);
		return builder.buildAccountComposite(decorations, parameters);
	}
	
	public void setDecorations(String [] decorations)
	{
		this.decorations=decorations;
	}
	
	private String [] getDecorations(String accountType)
	{
		return accountBuilderProperties.getDecorations(accountType);
	}
}
